<template>
  <div class="goTop">
    <img src="../../assets/img/返回顶部.png" @click="goTop" />
  </div>
</template>

<script>
export default {
  mounted() {
    this.goTop()
  },
  methods: {
    goTop() {
      //返回顶部
      let top = document.documentElement.scrollTop || document.body.scrollTop
      // 实现滚动效果
      const timeTop = setInterval(() => {
        document.body.scrollTop = document.documentElement.scrollTop = top -= 50
        if (top <= 0) {
          clearInterval(timeTop)
        }
      }, 10)

    }
  }
}
</script>

<style scoped>
.goTop {
  position: fixed;
  bottom: 60px;
  right: 30px;
  width: 50px;
  height: 50px;
}

img {
  width: 100%;
  height: 100%;
}
</style>